package cn.jjaw.command;

import cn.jjaw.command.note.load.LoadCommandWorker;
import cn.jjaw.command.worker.command.CommandExecute;
import cn.jjaw.command.worker.command.CommandWorker;
import cn.jjaw.command.worker.command.ExecuteResult;
import cn.jjaw.command.worker.complement.ComplementWorker;

public class CommandManager{
    CommandWorker commandWorker = new CommandWorker();
    ComplementWorker complementWorker = new ComplementWorker();

    /**
     * 添加一条命令
     */
    public CommandManager addCommand(CommandExecute commandExecute){
        commandWorker.add(commandExecute);
        return this;
    }
    /**
     * 将带有Command注解的静态命令添加到命令
     */
    public CommandManager addCommand(Class<?> theClass){
        LoadCommandWorker.load(commandWorker,theClass);
        return this;
    }
    /**
     * 将带有Command注解的实例方法添加到命令
     */
    public CommandManager addCommand(Object obj){
        LoadCommandWorker.load(commandWorker,obj);
        return this;
    }


    /**
     * 执行一条命令,已经被拆分成数组
     */
     public ExecuteResult execute(String[] command){
         return commandWorker.execute(command);
     }

    /**
     * 执行一条命令
     */
    public ExecuteResult execute(String command){
        return execute(command.split(" "));
    }
}
